package service

import (
	"naio/config"
	"naio/model"
)

type IBannerService interface {
	GetBannerList(status, page, size int) (*[]model.BannerModel, int)
	GetBannerById(id int) *model.BannerModel
	AddBanner(banner *model.BannerModel)
	UpdateBannerById(banner *model.BannerModel)
}

type BannerService struct {
	Conf *config.BaseConfig
}

func NewBannerService(conf *config.BaseConfig) IBannerService {
	return &BannerService{Conf: conf}
}

func (s *BannerService) GetBannerList(status, page, size int) (*[]model.BannerModel, int) {
	list, err := model.BrowseBanner(status, page, size)
	if err != nil {
		panic(err)
	}
	total := model.CountBanner(status)
	return list, total
}

func (s *BannerService) GetBannerById(id int) *model.BannerModel {
	one, err := model.GetBannerByID(id)
	if err != nil {
		panic(err)
	}
	return one
}
func (s *BannerService) AddBanner(banner *model.BannerModel) {
	err := model.CreateBanner(banner)
	if err != nil {
		panic(err)
	}
}
func (s *BannerService) UpdateBannerById(banner *model.BannerModel) {
	err := model.SaveBanner(banner)
	if err != nil {
		panic(err)
	}
}